package order.bean;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 订单步骤
 * @author: BacHe
 * @email: 1218585258@qq.com
 * @Date: 2020/12/8 22:30
 */
public class OrderStep {
    //订单编号
    private long orderId;
    //描述：创建订单,订单付款,订单推送,订单完成
    private String desc;
    //业务顺序：1创建订单,2订单付款,3订单推送,4订单完成
    private int order;

    public OrderStep() {
    }

    public OrderStep(long orderId, String desc) {
        this.orderId = orderId;
        this.desc = desc;
    }

    public long getOrderId() {
        return orderId;
    }

    public int getOrder() {
        return order;
    }

    public OrderStep setOrder(int order) {
        this.order = order;
        return this;
    }

    public OrderStep setOrderId(long orderId) {
        this.orderId = orderId;
        return this;
    }

    public String getDesc() {
        return desc;
    }

    public OrderStep setDesc(String desc) {
        this.desc = desc;
        return this;
    }

    @Override
    public String toString() {
        return "OrderStep{" +
                "orderId=" + orderId +
                ", desc='" + desc + '\'' +
                ", order=" + order +
                '}';
    }

    public static List<OrderStep> getList(){
        List<OrderStep> list = new ArrayList<>();
        list.add(new OrderStep().setOrderId(1L).setDesc("1.订单创建").setOrder(1));
        list.add(new OrderStep().setOrderId(1L).setDesc("2.订单付款").setOrder(2));
        list.add(new OrderStep().setOrderId(1L).setDesc("3.订单推送").setOrder(3));
        list.add(new OrderStep().setOrderId(1L).setDesc("4.订单完成").setOrder(4));

        list.add(new OrderStep().setOrderId(2L).setDesc("1.订单创建").setOrder(1));
        list.add(new OrderStep().setOrderId(2L).setDesc("2.订单付款").setOrder(2));
        list.add(new OrderStep().setOrderId(2L).setDesc("3.订单推送").setOrder(3));
        list.add(new OrderStep().setOrderId(2L).setDesc("4.订单完成").setOrder(4));

        list.add(new OrderStep().setOrderId(3L).setDesc("1.订单创建").setOrder(1));
        list.add(new OrderStep().setOrderId(3L).setDesc("2.订单付款").setOrder(2));
        list.add(new OrderStep().setOrderId(3L).setDesc("3.订单推送").setOrder(3));
        list.add(new OrderStep().setOrderId(3L).setDesc("4.订单完成").setOrder(4));

        list.add(new OrderStep().setOrderId(4L).setDesc("1.订单创建").setOrder(1));
        list.add(new OrderStep().setOrderId(4L).setDesc("2.订单付款").setOrder(2));
        list.add(new OrderStep().setOrderId(4L).setDesc("3.订单推送").setOrder(3));
        list.add(new OrderStep().setOrderId(4L).setDesc("4.订单完成").setOrder(4));

        list.add(new OrderStep().setOrderId(5L).setDesc("1.订单创建").setOrder(1));
        list.add(new OrderStep().setOrderId(5L).setDesc("2.订单付款").setOrder(2));
        list.add(new OrderStep().setOrderId(5L).setDesc("3.订单推送").setOrder(3));
        list.add(new OrderStep().setOrderId(5L).setDesc("4.订单完成").setOrder(4));
        //洗牌,乱序。
        Collections.shuffle(list);
        //按照order业务顺序排序
        list.sort((o1, o2) -> o1.order - o2.order);
        return list;
    }

    public static void main(String[] args) {
        //生成一批数据，用于发送消息。
        //同一个订单id，发送的业务是顺序的，发送MQ消息后，接收到消息，处理业务逻辑，也是顺序的。
        //用于测试顺序消息
        List<OrderStep> list = OrderStep.getList();
        list.forEach(System.out::println);
    }
 }
